package logic

import (
	"context"
	"user_srv/user"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderViewLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderViewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderViewLogic {
	return &OrderViewLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderViewLogic) OrderView(req *types.OrderViewRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	view, err := l.svcCtx.UserSrv.OrderView(l.ctx, &user.OrderViewRequest{
		UserId:  req.UserId,
		OrderId: req.HouseId,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "查看订单成功",
		Data: map[string]interface{}{
			"OrderSn":     view.OrderSn,
			"PayType":     view.PayType,
			"PayTime":     view.PayTime,
			"Amount":      view.Amount,
			"OrderStatus": view.OrderStatus,
		},
	}, nil
}
